/**
 * 08/dic/2011 - fabio.melillo@gmail.com
 */
package org.unisannio.interactive;

import org.unisannio.R;
import org.unisannio.remote.GenericRemote;
import org.unisannio.remote.RemoteContentProvider;
import org.unisannio.util.MovieMetaData;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.os.AsyncTask;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author fabio
 * 
 */
public class UpdateMoviesTask extends
		AsyncTask<GenericRemote, Integer, Integer> {

	private Activity activity;
	private ProgressDialog dialog;

	public UpdateMoviesTask(Activity activity) {
		this.activity = activity;
	}

	@Override
	protected void onPreExecute() {
		dialog = ProgressDialog.show(activity, "", "Querying. Please wait...",
				true);
	}

	@Override
	protected Integer doInBackground(GenericRemote... remote) {
		TextView args = (TextView) activity.findViewById(R.id.whereArgs);
		String[] valori = new String[1];
		String arg= args.getText().toString();
		valori[0] = arg;
		String where=MovieMetaData.MOVIE_TITLE_KEY+ " LIKE ? ";
		ContentValues contentValues=new ContentValues();
		contentValues.put(MovieMetaData.MOVIE_YEAR_KEY, 2222);
		int res=((RemoteContentProvider)remote[0]).update(MovieMetaData.CONTENT_URI, contentValues, where, valori);

		return res;
	}

	@Override
	protected void onPostExecute(Integer num) {
		dialog.dismiss();
		Toast toast = Toast.makeText(activity, num + " record aggiornati",
				Toast.LENGTH_SHORT);
		toast.show();

	}

}
